const React = require('react');
const { View, StyleSheet, Platform } = require('react-native');
const {
    JDDevice,
    JDDialog,
    JDConfirmDialog,
    JDTouchable,
    JDText,
    JDJumping,
    JDScrollView,
    JDRouter
} = require('@areslabs/jdreact-core-lib');
const { NavigationBar } = JDRouter;

class JDJumpingExample extends React.Component {
    state = {
        jumpAndroid_class_name_jd: 'com.jingdong.common.jdreactFramework.activities.JDReactNativeVersionCheck',
        jumpAndroidflag_class_name_jd: 'com.jingdong.common.jdreactFramework.activities.JDReactNativeVersionCheck',
        jumpAndroid_class_name: 'com.jingdong.global.app.jdreactFramework.activities.JDReactNativeVersionCheck',
        jumpAndroidflag_class_name: 'com.jingdong.global.app.jdreactFramework.activities.JDReactNativeVersionCheck',
        jumpAndroid_params_key: 'brand.json',
        jumpAndroid_params_json: "{'shopId':57025}",
        jumpToDeeplinkAndroid_class_name_jd: 'chargeactivity',
        jumpToDeeplinkAndroid_class_name: 'jshopnew',
        jumpToDeeplinkAndroid_params_key: '',
        jumpToDeeplinkAndroid_params_json: "",
        jumpAndroid_openapp_url: 'openapp.jdmobile://virtual?params={"category":"jump","des":"jdreactversion"}',
        jumpIOS_openapp_url: 'openApp.jdMobile://virtual?params={"category":"jump","des":"jshopBrand","cid":"","SE":"se","SI":"si","m_param":{"key1":"value1"}}',
        jumpAndroid_openapp_url: 'openapp.jdmobile://virtual?params={"category":"jump","des":"jdreactversion"}',
        jumpIOS_openapp_url: 'openjdthai://virtual?params={"category":"jump","des":"jshopBrand","cid":"","SE":"se","SI":"si","m_param":{"key1":"value1"}}',
        jumpIos_class_name: 'JDShopHomeViewController',
        jumpIos_params_key: 'alloc',
        jumpIos_params_json: '[{"funcName": "initWithControllerWithVenderId:withShopId:","params": ["18833","18833"]}]',
        jumpIos_Type: '0',
        shopId: '57025',
        // web_url: 'https://1.m.jd.com'
        web_url: 'https://pro.m.jd.com/mall/active/41b4iv8KfAkxcxzgvTbEpZ6UYDNB/index.html',
    };

    render() {
        return (
            <View style={styles.wrapper}>
                <NavigationBar Title="JDJumping组件" />
                <JDScrollView style={styles.body}>
                {this.renderCommon()}
                <View style={{height: 30}}></View>
                </JDScrollView>
            </View>
        );
    }

    renderCommon = () => {
        return (
            <View>
                <View><JDText>Common API</JDText></View>
                <View>
                    <JDTouchable onPress={() => {
                        JDJumping.jumpToOpenapp(Platform.OS === 'iOS' ? this.state.jumpIOS_openapp_url : this.state.jumpAndroid_openapp_url).catch(err => alert(err))
                    }}>
                        <View style={styles.btn}>
                            <JDText style={styles.btnText}>JDJumping.jumpToOpenapp</JDText>
                        </View>
                    </JDTouchable>
                </View>

                <View>
                    <JDTouchable onPress={() => {
                        JDJumping.jumpToWeb(this.state.web_url).catch(err => alert(err))
                    }}>
                        <View style={styles.btn}>
                            <JDText style={styles.btnText}>JDJumping.jumpToWeb</JDText>
                        </View>
                    </JDTouchable>
                </View>
            </View>
        );
    };
}

const styles = StyleSheet.create({
    wrapper: {
        flex: 1
    },
    body: {
        flex: 1,
        padding: JDDevice.getRpx(20)
    },
    btn: {
        borderRadius: JDDevice.getDpx(4),
        backgroundColor: '#f23030',
        justifyContent: 'center',
        alignItems: 'center',
        height: JDDevice.getRpx(80),
        marginBottom: JDDevice.getRpx(20)
    },
    btnText: {
        color: '#FFF'
    },
    customDialogStyle: {
        borderWidth: 5,
        borderColor: '#F00'
    },
    dialogContent: {},
    title: {
        height: JDDevice.getRpx(80),
        borderBottomWidth: JDDevice.getDpx(1),
        borderColor: '#555',
        paddingLeft: JDDevice.getRpx(20),
        alignItems: 'center',
        justifyContent: 'center'
    },
    dialogBody: {
        flex: 1,
        alignItems: 'center',
        justifyContent: 'center',
        paddingLeft: JDDevice.getRpx(20),
        height: JDDevice.getRpx(340)
    }
});
module.exports = JDJumpingExample;
